<template>
  <el-dialog
    v-if="dialogVisible"
    v-model="dialogVisible"
    title="预览新闻"
    class="news-preview-dialog"
    @close="handelCancel"
  >
    <div>
      <h1
        style="
          border-bottom: 1px solid #ccc;
          box-sizing: border-box;
          padding-bottom: 10px;
        "
      >
        {{ itemData.title }}
      </h1>
      <div
        style="
          margin-block: 10px 20px;
          display: flex;
          justify-content: space-between;
        "
      >
        <div>创建时间：{{ itemData.createdAt }}</div>
        <div>
          发布状态：{{ itemData.isPublish === 1 ? "已发布" : "未发布" }}
        </div>
      </div>
      <div class="editor-content-view" v-html="itemData.content"></div>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="handelCancel">关闭</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
export default {
  name: "PreviewDialog",
};
</script>
<script setup>
import { ref, watch } from "vue";

const props = defineProps({
  modelValue: Boolean,
  itemData: Object,
});
const emit = defineEmits(["update:modelValue"]);

const dialogVisible = ref(false);

// 关闭弹窗
const handelCancel = () => {
  dialogVisible.value = false;
  emit("update:modelValue", false);
};

watch(
  () => props.modelValue,
  (newValue) => {
    dialogVisible.value = newValue;
  }
);
</script>

<style lang="scss">
.news-preview-dialog {
  margin: 0 !important;
  padding-inline: 0;
  display: flex;
  flex-direction: column;
  width: 80%;
  height: 80vh;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  .el-dialog__header {
    padding-inline: 20px;
    box-sizing: border-box;
  }
  .el-dialog__body {
    flex: 1;
    overflow: auto;
    & > div {
      padding-inline: 20px;
      box-sizing: border-box;
    }
  }
  .el-dialog__footer {
    padding-inline: 20px;
    box-sizing: border-box;
  }
  /*  table,
  td,
  th {
    border: 1px solid black;
    border-collapse: collapse;
  } */
}
</style>